import { ResourceComment, ResourceUp, Report, ResourceBoost, ChatMessage } from '@boticord/resources-client'
import { Column, Entity, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryColumn, JoinColumn } from 'typeorm'
import { Badge } from './badge.model'
import { UserWebhook } from '@boticord/users-client/models/webhook.model'

// this types will be used to identify which icon to display for each badge
export enum UserLinkTypes {
  Vk = 'vk',
  Telegram = 'telegram',
  Donate = 'donate',
  Git = 'git',
  Custom = 'custom'
}

@Entity()
export class User {
  @PrimaryColumn()
  declare id: string

  @Column()
  declare discriminator: string

  @Column()
  declare username: string

  @Column({ nullable: true, default: null })
  declare description?: string

  @Column({ nullable: true, default: null })
  declare shortDescription?: string

  @ManyToMany(() => Badge)
  @JoinTable()
  declare badges: Badge[]

  @Column({ nullable: true, type: 'json', default: null })
  declare socials?: Record<UserLinkTypes, string | undefined>

  @Column({ nullable: true, default: null })
  declare shortDomain?: string

  @Column({ nullable: true, default: null })
  declare avatar?: string

  @OneToMany(() => ResourceComment, c => c.author, { cascade: [ 'remove' ] })
  declare comments: ResourceComment[]

  @OneToMany(() => Report, r => r.resource, { cascade: [ 'remove' ] })
  declare reports: Report[]

  @OneToMany(() => ResourceUp, up => up.user, { cascade: [ 'remove' ] })
  declare ups: ResourceUp[]

  @OneToMany(() => ResourceBoost, boost => boost.user, { cascade: [ 'remove' ] })
  declare boosts: ResourceBoost[]

  @OneToMany(() => ChatMessage, c => c.author, { cascade: [ 'remove' ] })
  declare messages: ChatMessage[]

  @JoinColumn()
  @OneToOne(() => UserWebhook, w => w.user, {
    nullable: true, cascade: true,
  })
  declare webhook?: UserWebhook
}
